﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data.OleDb;
using System.Data;
using Common.Logging;

namespace DALFactory.DataBase
{
    public class AccessHelper
    {
        ILog log = LogManager.GetLogger("App-Info");
        private static readonly string DataBasePath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, string.Format("DataBase{0}Config.mdb", Path.DirectorySeparatorChar));

        private readonly string ConnectionStr = string.Format("Provider=SQLOLEDB;Data Source=192.168.1.240;Database=transfer;User ID=sa;Password=1;Trusted_Connection=False");

        public OleDbConnection GetConnection()
        {
            OleDbConnection con=new OleDbConnection(ConnectionStr);
            return con;
        }
         public OleDbDataAdapter GetDataAdapter(string text, OleDbConnection con)
        {
            OleDbDataAdapter da = new OleDbDataAdapter(text, con) ;
             return da;
        }
        public DataSet GetDataSet(CommandType commandType, string commandText)
        {
            OleDbConnection con=GetConnection();
            OleDbDataAdapter da = GetDataAdapter(commandText,con);
            DataSet ds=new DataSet();
            da.Fill(ds);
            return ds;

        }
        public void ExecuteNonQuery(CommandType commandType, string commandText)
        {
             OleDbConnection con=GetConnection();
            //try
            //{
             
            OleDbCommand cmd=new OleDbCommand(commandText,con);
            con.Open();
            cmd.ExecuteNonQuery();
            //}
            //catch(Exception ex)
            //{
            //    log.Debug(ex);
            //}
            //finally{
            //con.Close();
            //    con.Dispose();
            //}
            
            
        }
    }
}
